package com.wu.server.dao;

import com.wu.server.entity.Goods;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

public interface NewGoodsRepository extends JpaRepository<Goods, Long> {
    @Query(value = "select * from jd_shop.goods where " +
            "(jd_shop.goods.id = ?1 or ?1 is null) and" +
            "(jd_shop.goods.title like ?2 or ?2 is null) and" +
            "(jd_shop.goods.shop_name like ?5 or ?5 is null) and"+
            "(jd_shop.goods.tag_name like ?6 or ?6 is null) and"+
            "(jd_shop.goods.shop_name like ?7 or ?7 is null) and"+
            "(jd_shop.goods.prince between ?3 and ?4 or ?4 is null and ?3 is null)"
            , nativeQuery = true)
    Page<Goods> findAllBy(String id,String goodsName, String price1, String price2, String isSelf, String tagName, String shopName, Pageable pageable);

    // 删除商品
    @Transactional
    @Modifying
    @Query(value = "delete from jd_shop.goods where id = ?1", nativeQuery = true)
    void deleteGoods(int id);
}
